<?php
  if (!defined('EXPONENT')) exit('');
    if(exponent_users_isLoggedIn())
    {   
        global $user;
        $meeting=null;
        $loc->src='@meeting_mail_'.LANG.'-';
        $config = $db->selectObject('profilemodule_meeting_config',"location_data='".serialize($loc)."'");
        $metting_field= array('meeting_date','meeting_duration','meeting_place','meeting_language','meeting_type','meeting_record','related_lawyer','new_subject','meeting_notes','mentor_request','mentor_location','translator_request','mentor_required');
       
        foreach ($_REQUEST as $key => $value)
        {

            $config->mail_to_customer = str_replace( '%%'.$key, $value, $config->mail_to_customer ); 
            $config->mail_to_admin = str_replace( '%%'.$key, $value, $config->mail_to_admin ); 
            if (in_array($key, $metting_field))
            $meeting->$key=$_REQUEST[$key];
            
        }

        $meeting->meeting_date=strtotime($_REQUEST['meeting_date']);
        $meeting->user_id=$user->id;
        $meeting->last_update=time();
        $meeting->last_update_by=$user->firstname.' '.$user->lastname."({$user->username})";
        $meeting->user_target=$user->firstname.' '.$user->lastname."({$user->username})";
        $meeting->email=$user->email;
        $meeting->request_date=time();
        $meeting->approve_date=0;
        $meeting->approve_by='';
        $meeting->approve_state=0;
        $meeting->approve_note="";
        $meeting->email=$user->email;

        
        $db->insertObject($meeting,'profilemodule_meeting');
        //other
        $config->mail_to_admin = str_replace( '%%now', date("F j, Y, g:i a"), $config->mail_to_admin ); 
        $config->mail_to_admin = str_replace( '%%useremail',$user->email, $config->mail_to_admin );
        $config->mail_to_admin = str_replace( '%%username', $user->username, $config->mail_to_admin );
        $config->mail_to_customer = str_replace( '%%username', $user->username, $config->mail_to_customer );
        
        //save to database
        
        $mail_list=explode(',', $config->mail_list);
        //send admin
        $send_admin=profilemodule::SendMail($config->mail_to_admin_title, $config->mail_to_admin, 1, $mail_list, true,$user->email,$user->username);
        //send customer
        $send_custom=profilemodule::SendMail($config->mail_to_customer_title, $config->mail_to_customer, 1,$user->email ,false,SMTP_FROMADDRESS,SMTP_FROMADDRESS);
        if($send_custom&&$send_admin)
        {
            echo 'success';
        }
        else
        {
            echo 'failure';
        }

    }
?>
